package com.nervenets.template.service.subpub;

import cn.hutool.core.date.StopWatch;
import com.alibaba.fastjson.JSON;
import com.nervenets.general.redis.RedisSubPubManager;
import com.nervenets.general.utils.NumberUtil;
import com.nervenets.template.hibernate.domain.user.Manager;
import lombok.SneakyThrows;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * Created by joe on 2024/2/20.
 */
@Component
public class PubMessageHandler extends RedisSubPubManager<Manager> {

    @Override
    public String getChannel() {
        return "null";
    }

    @SneakyThrows
    @Override
    public void message(Manager body) {
        System.out.printf("收到消息  %s%n", JSON.toJSONString(body));
        StopWatch stopWatch = new StopWatch("消息消费");
        stopWatch.start();
        Thread.sleep(NumberUtil.randomNumber(5000, 12000));
        stopWatch.stop();
        System.out.println("执行完成" + body.getId() + stopWatch.shortSummary(TimeUnit.MILLISECONDS));
    }
}
